package com.yr.ryjk.hospital.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.yr.ryjk.hospital.entity.Hospital;
import com.yr.ryjk.hospital.vo.HospitalVO;

public interface HospitalMapper {
    int deleteByPrimaryKey(String id);

    int insert(Hospital record);

    int insertSelective(Hospital record);

    Hospital selectByPrimaryKey(String id);

    int updateByPrimaryKeySelective(Hospital record);

    int updateByPrimaryKey(Hospital record);

    @Select("select * from hospital where name=#{0}")
    @ResultMap("BaseResultMap")
	Hospital selectByName(String hospitalName);

 //   @Select("select h.*,d1.d_name as county,d2.d_name as city,d3.d_name as province "+
 //   		"from hospital h "+
 //   		"left join district d1 on h.d_id=d1.id "+
 //   		"left join district d2 on d2.id=d1.d_parent_id "+
 //   		"left join district d3 on d3.id=d2.d_parent_id "+
 //   		"limit #{0},#{1}")
//    @ResultMap("VoResultMap")
	List<HospitalVO> selectOfPage(int i, int pageSize,
			@Param("province") String province,
			@Param("city") String city,
			@Param("county") String county);
	
	int selectCount(@Param("province") String province,
			@Param("city") String city,
			@Param("county") String county);

    @Select("select h.*,d1.id as county,d2.id as city,d3.id as province "+
    		"from hospital h "+
    		"left join district d1 on h.d_id=d1.id "+
    		"left join district d2 on d2.id=d1.d_parent_id "+
    		"left join district d3 on d3.id=d2.d_parent_id "+
    		"where h.id=#{0} order by h.d_id ASC")
    @ResultMap("VoResultMap")
	HospitalVO selectById(String id);

    @Update("update hospital set name=#{1},level=#{2},location=#{3},d_id=#{4} where id=#{0}")
	void updateById(String id, String name, String level,
			String location, String county);

    @Select("select id,name from hospital where name like concat('%',#{name},'%')")
    @ResultMap("BaseResultMap")
	List<Hospital> selectLikely(@Param("name")String name);
	
	@Select("select * from hospital")
	@ResultMap("BaseResultMap")
	List<Hospital> selectAllHospital();
}